package com.xuecheng.media.controller;

import com.xuecheng.api.media.model.api.MediaApi;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.vo.MediaAuditVO;
import com.xuecheng.api.media.model.vo.MediaVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 媒资信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class MediaController implements MediaApi {

    @Autowired
    private MediaService  mediaService;


    @PostMapping("media")
    public MediaDTO createMedia(@RequestBody MediaVO vo){

        MediaDTO dto = MediaConvert.INSTANCE.entity2dto(vo);

        dto.setCompanyId(SecurityUtil.getCompanyId());


        return mediaService.createMedia(dto) ;
    }

    @PostMapping("media/list")
    public PageVO<MediaDTO> queryMedia( PageRequestParams params, @RequestBody MediaVO vo){
        Long companyId = SecurityUtil.getCompanyId();

        return mediaService.queryMedia(params,vo,companyId);

    }

    @Override
    @DeleteMapping("/media/{mediaId}")
    public void removeMedia(@PathVariable int mediaId) {

        Long companyId = SecurityUtil.getCompanyId();

         mediaService.removeMedia(mediaId,companyId);
    }


}
